cmake_minimum_required(VERSION 3.8)
project(agiros_xf_bridge)

# 必须先加载 ament 和 ROS 2 依赖
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)

# 编译器选项
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# 可执行文件配置
add_executable(v2t 
  src/v2t.cpp 
  src/speech_recognizer.c 
  src/linuxrec.c
)

# 必须在 target_link_libraries 之前声明依赖
ament_target_dependencies(v2t
  rclcpp
  std_msgs
  geometry_msgs
)

# 链接库
target_link_libraries(v2t
  libmsc.so 
  -ldl -lpthread -lm -lrt -lasound
)

# 头文件目录
target_include_directories(v2t PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
)

# 安装规则
install(TARGETS v2t
  DESTINATION lib/${PROJECT_NAME}
)

install(
  DIRECTORY include/
  DESTINATION include
)

# 测试配置（可选）
if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  set(ament_cmake_copyright_FOUND TRUE)
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

# 必须放在最后
ament_package()